package br.edu.unilasalle.simon_api.rs;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;

import br.edu.unilasalle.simon_api.domain.Cliente;
import br.edu.unilasalle.simon_api.service.IClienteService;

@Path("/cliente")
public class ClienteRS {
	
	@Autowired
	private IClienteService service;
	
	@GET
    @Produces(MediaType.APPLICATION_JSON)
    public List<Cliente> findAllCliente() {
		return service.findAllCliente();
    }
	
	@GET
    @Path("/query")
    @Produces(MediaType.APPLICATION_JSON)
    public List<Cliente> findAllByNomeOrSobrenome(@QueryParam("param") String param) {
        return service.findAllByNomeOrSobrenome(param);
    }

    @GET
    @Path("{id}")
    @Produces(MediaType.APPLICATION_JSON)
    public Cliente findById(@PathParam("id") long id) {
        return service.findById(id);
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Cliente create(Cliente obj) {
        return service.save(obj);
    }

    @PUT
    @Path("{id}")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Cliente update(Cliente obj) {
    	service.save(obj);
    	return obj;
    }

    @DELETE
    @Path("{id}")
    @Produces(MediaType.APPLICATION_JSON)
    public void delete(@PathParam("id") long id) {
    	service.deleteById(id);
    }

}
